//
// Created by Key-Box-Min on 21/06/2020.
//

#include "CThread.h"

/**
 *
//    AtomicList<std::string,int> list;
    std::list<std::string> mmm;
    AtomicLock lock;
    std::shared_mutex mutex;
    std::string sss = "ssssss";

    std::thread t([&](){
        for(int i=0;i<(2*2+4)*5;i++){
//            AtomicLock_Readguard l(&lock);
            std::shared_lock<std::shared_mutex> l(mutex);
//            std::cout<<"A"<<sss<<"  "<<lock.readCount()<<" "<<lock.isLock()<<std::endl;
//            mmm.push("a",i);

            std::string s("  ");
            mmm.push_back(s);
            std::this_thread::sleep_for(std::chrono::milliseconds (5));
        }
    });

    std::thread t1([&](){
        for(int i=0;i<5;i++){
            AtomicLock_Readguard l(&lock);
//            std::shared_lock<std::shared_mutex> l(mutex);
//            std::cout<<"A"<<sss<<"  "<<lock.readCount()<<" "<<lock.isLock()<<std::endl;
//            mmm.push("a",i);

            std::string s("a");
            char buf[20];
            _itoa_s(i,buf,sizeof(buf),10);
            for(int i=0;i<20;i++)s.push_back(buf[i]);
            mmm.push_back(s);
            std::this_thread::sleep_for(std::chrono::milliseconds (10));
        }
    });
    std::thread t2([&](){
        for(int i=0;i<5;i++){
            AtomicLock_Readguard l(&lock);
//            std::shared_lock<std::shared_mutex> l(mutex);
//            std::cout<<"B"<<sss<<"  "<<lock.readCount()<<" "<<lock.isLock()<<std::endl;
//            mmm.push("b",i);
//            mmm.push_back(std::string("b")+i);

            std::string s("b--");
            char buf[20];
            _itoa_s(i,buf,sizeof(buf),10);
            for(int i=0;i<20;i++)s.push_back(buf[i]);
            mmm.push_back(s);
            std::this_thread::sleep_for(std::chrono::milliseconds (20));
        }
    });
//    std::atomic_int cou = 0;
    std::thread t3([&](){
        for(int i=0;i<5;i++){
            AtomicLock_guard l(&lock);
//            std::unique_lock<std::shared_mutex> l(mutex);
//            std::cout<<"C------"<<sss<<"  "<<lock.readCount()<<" "<<lock.isLock()<<std::endl;
//            mmm.push("b",i);
//            mmm.push_back(std::string("c")+i);
//
            std::string s("c----");
            char  buf[20];
            _itoa_s(i,buf,sizeof(buf),10);
            for(int i=0;i<20;i++)s.push_back(buf[i]);
            mmm.push_back(s);
            std::this_thread::sleep_for(std::chrono::milliseconds (10));
        }
//        std::string a;
//        int b;
//        while(true){
//            if(list.pop(a,b)){
//                std::cout<<a<<" "<<b<<std::endl;
//                cou++;
//            }else{
//                std::this_thread::sleep_for(std::chrono::seconds(1));
//                if(list.empty())return;
//            }
//        }
    });

    t1.join();
    t2.join();
    t3.join();
    t.join();
    for(auto i : mmm){
        std::cout<<i<<std::endl;
    }

 * */

//    CThread<void(int)> t([](int a)->void{
//        std::cout<<"aaa"<<a<<std::endl;
////        std::this_thread::sleep_for(std::chrono::seconds(3));
////        return 34;
//    },3);
//    t.start(7);
//
//    t.get_future().get();
//
//    std::cout<<"vvv"<<std::endl;
//    t.join();